package com.thrift.distributed.process;

import lombok.extern.slf4j.Slf4j;

/**
 * @包名称 com.thrift.distributed.process
 * @类描述 <pre></pre>
 * @作者 zhangbo
 * @创建时间 2019/9/21
 * @版本 1.00
 * @修改记录 <pre>
 *     版本           修改人         修改日期         修改内容描述
 *     -----------------------------------------------------------
 *     1.00           Lenovo        2019/9/21
 *     -----------------------------------------------------------
 * </pre>
 */
@Slf4j
public class RegistRunable implements Runnable {

    private ZKRegistServer zkRegistServer;

    /*注册中心超时或重复检测休眠时间*/
    private int zookeeperServiceSleepTime;

    public RegistRunable(ZKRegistServer zkRegistServer, int zookeeperServiceSleepTime) {
        this.zkRegistServer = zkRegistServer;
        this.zookeeperServiceSleepTime = zookeeperServiceSleepTime;
    }

    @Override
    public void run() {
        while (true) {
            zkRegistServer.init();
            try {
                Thread.sleep(zookeeperServiceSleepTime);
            } catch (InterruptedException e) {
                log.error("守护线程中断，重新启动新守护线程：{}", e);
                new Thread(new RegistRunable(zkRegistServer, zookeeperServiceSleepTime)).start();
                log.info("新守护线程启动成功");
                Thread.currentThread().interrupt();
            }
        }
    }

}
